package com.apigen.platform.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 数据表视图对象
 *
 * @author API Generator Platform
 * @since 2025-09-24
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "数据表信息")
public class DatabaseTableVO {

    @Schema(description = "表ID", example = "1")
    private Long tableId;

    @Schema(description = "表名称", example = "sys_user")
    private String tableName;

    @Schema(description = "表描述", example = "系统用户表")
    private String tableComment;

    @Schema(description = "表类型", example = "TABLE")
    private String tableType;

    @Schema(description = "存储引擎", example = "InnoDB")
    private String engine;

    @Schema(description = "字符集", example = "utf8mb4")
    private String charset;

    @Schema(description = "排序规则", example = "utf8mb4_unicode_ci")
    private String collation;

    @Schema(description = "自增起始值", example = "1000")
    private Long autoIncrement;

    @Schema(description = "所属项目ID", example = "1")
    private Long projectId;

    @Schema(description = "所属项目名称", example = "用户管理系统")
    private String projectName;

    @Schema(description = "创建者ID", example = "1000")
    private Long creatorId;

    @Schema(description = "创建者名称", example = "admin")
    private String creatorName;

    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    private LocalDateTime updateTime;

    @Schema(description = "字段数量", example = "8")
    private Integer fieldCount;

    @Schema(description = "索引数量", example = "3")
    private Integer indexCount;

    @Schema(description = "数据行数", example = "1500")
    private Long dataRows;

    @Schema(description = "表大小(KB)", example = "256")
    private Long tableSize;

    @Schema(description = "字段列表")
    private List<DatabaseFieldVO> fields;

    @Schema(description = "索引列表")
    private List<DatabaseIndexVO> indexes;

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "数据表字段信息")
    public static class DatabaseFieldVO {

        @Schema(description = "字段ID", example = "1")
        private Long fieldId;

        @Schema(description = "字段名称", example = "user_id")
        private String fieldName;

        @Schema(description = "字段类型", example = "BIGINT")
        private String fieldType;

        @Schema(description = "字段长度", example = "20")
        private Integer fieldLength;

        @Schema(description = "字段精度", example = "10")
        private Integer fieldPrecision;

        @Schema(description = "字段小数位", example = "2")
        private Integer fieldScale;

        @Schema(description = "是否可空", example = "false")
        private Boolean isNullable;

        @Schema(description = "是否主键", example = "true")
        private Boolean isPrimaryKey;

        @Schema(description = "是否自增", example = "true")
        private Boolean isAutoIncrement;

        @Schema(description = "是否唯一", example = "false")
        private Boolean isUnique;

        @Schema(description = "默认值", example = "0")
        private String defaultValue;

        @Schema(description = "字段注释", example = "用户ID")
        private String fieldComment;

        @Schema(description = "排序", example = "1")
        private Integer sortOrder;

        @Schema(description = "Java类型", example = "Long")
        private String javaType;

        @Schema(description = "JDBC类型", example = "BIGINT")
        private String jdbcType;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "数据表索引信息")
    public static class DatabaseIndexVO {

        @Schema(description = "索引名称", example = "idx_user_name")
        private String indexName;

        @Schema(description = "索引类型", example = "NORMAL")
        private String indexType;

        @Schema(description = "是否唯一", example = "false")
        private Boolean isUnique;

        @Schema(description = "索引字段", example = "user_name,email")
        private String indexColumns;

        @Schema(description = "索引注释", example = "用户名索引")
        private String indexComment;
    }
}











